package com.web.base.auth.util;

import com.blue.jdbc.Page;
import com.web.base.auth.message.MenuButtonRequest;
import com.web.base.auth.message.MenuButtonResponse;
import com.web.base.auth.model.MenuButton;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 菜单按钮转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月15日
 */
public class MenuButtonConvertor
{
	private MenuButtonConvertor()
	{
	}
	
	public static MenuButton toMenuButton(MenuButtonRequest request)
	{
		if (request == null)
			return null;
		
		MenuButton menuButton = new MenuButton();
		menuButton.setId(request.getId());
		menuButton.setAppId(request.getAppId());
		menuButton.setMenuId(request.getMenuId());
		menuButton.setCode(request.getCode());
		menuButton.setName(request.getName());
		menuButton.setDescp(request.getDescp());
		menuButton.setState(request.getState());
		return menuButton;
	}
	
	public static MenuButtonResponse toResponse(MenuButton menuButton)
	{
		if (menuButton == null)
			return null;
		
		MenuButtonResponse response = new MenuButtonResponse();
		response.setId(menuButton.getId());
		response.setAppId(menuButton.getAppId());
		response.setMenuId(menuButton.getMenuId());
		response.setCode(menuButton.getCode());
		response.setName(menuButton.getName());
		response.setDescp(menuButton.getDescp());
		response.setState(menuButton.getState());
		response.setSelected(menuButton.getSelected());
		return response;
	}
	
	public static List<MenuButtonResponse> toResponse(List<MenuButton> list)
	{
		List<MenuButtonResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (MenuButton menuButton : list)
		{
			responseList.add(toResponse(menuButton));
		}
		return responseList;
	}
	
	public static Map<Integer, MenuButtonResponse> toResponse(Map<Integer, MenuButton> map)
	{
		Map<Integer, MenuButtonResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, MenuButton> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<MenuButtonResponse> toResponse(Page<MenuButton> page)
	{
		if (page == null)
			return null;
		
		Page<MenuButtonResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
